<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select @change="handleChangeMEQG" v-model="listQuery.U_MEQG" placeholder="设备组" clearable style="width: 120px;margin-right:10px" class="filter-item">
        <el-option v-for="item in MEQGOptions" :key="item.value" :label="item.value" :value="item.label" />
      </el-select>
      <el-select v-model="listQuery.U_MEQU" placeholder="设备编号" clearable style="width: 120px;margin-right:10px" class="filter-item">
        <el-option v-for="item in MEQUOptionsfilters" :key="item" :label="item" :value="item" />
      </el-select>
      <el-input placeholder="批号" v-model="curFilterLotId" clearable style="width: 120px;margin-right:10px" class="filter-item">
      </el-input>
      <el-input placeholder="产品" v-model="curFilterMatId" clearable style="width: 120px;margin-right:10px" class="filter-item">
      </el-input>
      <el-select v-model="listQuery.Canceled" placeholder="状态" clearable class="filter-item" style="width: 120px;margin-right:10px">
        <el-option v-for="item in ['Y','N']" :key="item" :label="item=='Y'?'已取消':'正常'" :value="item" />
      </el-select>
      <el-date-picker
        v-model="dtPicker"
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        class="filter-item"
        style="margin-right:10px"
        @change="datepickerChange($event)"
        :picker-options="pickerOptions">
      </el-date-picker>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
      <el-button class="filter-item" :loading="downloadLoading" type="success" icon="el-icon-document" @click="handleDownload">
        导出
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="单据号" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.DocEntry }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="设备组">
        <template slot-scope="scope">
          <span>{{ scope.row.MEQG_Name }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="设备编号">
        <template slot-scope="scope">
          <span>{{ scope.row.U_MEQU }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="150px" align="center" label="批号">
        <template slot-scope="scope">
          <span>{{ scope.row.lot_id }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="100px" align="center" label="产品">
        <template slot-scope="scope">
          <span>{{ scope.row.U_ItemCode }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80px" align="center" label="产出数量">
        <template slot-scope="scope">
          <span>{{ scope.row.U_Qty }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80px" align="center" label="投入数量">
        <template slot-scope="scope">
          <span>{{ scope.row.U_InQty }}</span>
        </template>
      </el-table-column>

      <el-table-column v-if="false" width="120px" align="center" label="LOT操作">
        <template slot-scope="scope">
          <span>{{ scope.row.U_MPCO }}</span>
        </template>
      </el-table-column>

      <el-table-column v-if="false" width="120px" align="center" label="Lot状态">
        <template slot-scope="scope">
          <span>{{ scope.row.U_MLOT }}</span>
        </template>
      </el-table-column>


<!--      <el-table-column width="80px" align="center" label="MinDocEntry">
        <template slot-scope="scope">
          <span>{{ scope.row.minDocEntry }}</span>
        </template>
      </el-table-column> -->

      <el-table-column width="80px" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.Canceled == 'Y' ? '已取消' : '正常'}}</span>
        </template>
      </el-table-column>

      <el-table-column width="80px" align="center" label="操作选项">
        <template slot-scope="scope">
          <span>{{ scope.row.U_OperParm }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="生产数据">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.Canceled == 'Y' || (MEQGDataInputRole.indexOf(scope.row.U_MEQG) < 0)" @click="$router.push('/mpcpend/edit/'+scope.row.DocEntry+'?at=1&U_BOUDF='+scope.row.scbh+'&U_ItemCode='+encodeURIComponent(scope.row.U_ItemCode)+'&lotid='+encodeURIComponent(scope.row.lot_id))" :type="scope.row.scbh_qty == 0?'danger':'success'" plain>
            {{ scope.row.scbh_Existed ? (scope.row.scbh_qty == 0 ? '未录' : '已录') : '无标'}}
          </el-button>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="质量数据">
        <template slot-scope="scope">
          <el-button :disabled="(scope.row.Canceled == 'Y' || scope.row.U_MEQG == 'SH') || MEQGDataInputRole.indexOf('ZL') < 0" @click="$router.push('/mpcpend/edit/'+scope.row.minDocEntry+'?at=1&U_BOUDF='+scope.row.zlbh+'&U_ItemCode='+encodeURIComponent(scope.row.U_ItemCode)+'&lotid='+encodeURIComponent(scope.row.lot_id))" :type="scope.row.zlbh_qty == 0?'danger':'success'" plain >
            {{ scope.row.zlbh_Existed ? (scope.row.zlbh_qty == 0 ? '未录' : '已录') : '无标'}}
          </el-button>
        </template>
      </el-table-column>

      <el-table-column width="180px" align="center" label="执行时间">
        <template slot-scope="scope">
          <span>{{ scope.row.CreateDate + ' ' +scope.row.CreateTime.padStart(4,'0').substr(0,2) +':' + scope.row.CreateTime.padStart(4,'0').substr(2,2)+":00"}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" min-width="220px">
        <template slot-scope="scope">
          <router-link v-if="scope.row.Canceled == 'N' && scope.row.U_MPCO == 'end'" :disabled="scope.row.Canceled == 'Y' || (MEQGDataInputRole.indexOf(scope.row.U_MEQG) < 0)" :event="!(scope.row.Canceled == 'Y' || (MEQGDataInputRole.indexOf(scope.row.U_MEQG) < 0)) ? 'click' : ''" :to="'/mpcpend/edit/'+scope.row.DocEntry+'?at=1&U_BOUDF='+scope.row.scbh+'&U_ItemCode='+encodeURIComponent(scope.row.U_ItemCode)+'&lotid='+encodeURIComponent(scope.row.lot_id)" style="margin-right:10px;">
            <el-button :disabled="scope.row.Canceled == 'Y' || (MEQGDataInputRole.indexOf(scope.row.U_MEQG) < 0)" type="success" size="small" icon="el-icon-edit" >
              生产数据
            </el-button>
          </router-link>

          <router-link v-if="scope.row.Canceled == 'N' && scope.row.U_MPCO == 'end'" :disabled="(scope.row.Canceled == 'Y' || scope.row.U_MEQG == 'SH') || MEQGDataInputRole.indexOf('ZL') < 0" :event="!((scope.row.Canceled == 'Y' || scope.row.U_MEQG == 'SH') || MEQGDataInputRole.indexOf('ZL') < 0) ? 'click' : ''" :to="'/mpcpend/edit/'+scope.row.minDocEntry+'?at=1&U_BOUDF='+scope.row.zlbh+'&U_ItemCode='+encodeURIComponent(scope.row.U_ItemCode)+'&lotid='+encodeURIComponent(scope.row.lot_id)">
            <el-button :disabled="(scope.row.Canceled == 'Y' || scope.row.U_MEQG == 'SH') || MEQGDataInputRole.indexOf('ZL') < 0" type="warning" size="small" icon="el-icon-edit">
              质检数据
            </el-button>
          </router-link>

        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogTableVisible" title="MPCP Detail" >
      <el-table :data="mpcp1detail">
        <el-table-column property="DocEntry" label="单据号" width="100" />
        <el-table-column property="LineId" label="行号" width="80" />
        <el-table-column property="U_MLOO" label="LOT操作对象" />
        <el-table-column property="U_Ostate" label="状态" />
      </el-table>
      <div style="margin-top:20px;">
        <el-button type="warning" :disabled="curMPCP.Canceled == 'Y'" @click="onSubmitBacktoLastProcess">撤回操作</el-button>
        <el-button @click="dialogTableVisible = false">取消</el-button>
      </div>
    </el-dialog>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { getAllMPCPendDataLists, fetchMPCPends, fetchMPCP1s, processBacktoPreviousMPCPs, fetchList, fetchMLOOsByDocEntry, fetchBouddGeDocEntry, fetchEDCs } from '@/api/res'
import { parseDate, dateAddDays, unique } from '@/utils'
import { getUserInfo } from '@/utils/auth'
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'MpcpendList',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      list: null,
      flist: null,
      total: 0,
      listLoading: true,
      downloadLoading: false,
      filename: '',
      autoWidth: true,
      bookType: 'xlsx',
      listQuery: {
        page: 1,
        limit: 20,
        U_MEQU:'',
        U_MPCO:'',
        U_MEQG:'',
        Canceled:'N'
      },
      resList:[],
      MEQUOptions:[],
      MEQUOptionsfilters:[],
      MPCOOptions:[],
      MEQGOptions:[{label:'HJ',value:'混胶工程'},{label:'TB',value:'涂布工程'},{label:'SH',value:'熟化工程'},{label:'FQ',value:'分切工程'}],
      MEQGCodes:['HJ','TB','SH','FQ'],
      curMEQGCode:'',
      curFilterLotId:'',
      curFilterMatId:'',
      mpcp1detail:[],
      curMPCP:'',
      dialogTableVisible:false,
      userInfoRoles:[],
      MEQGDataInputRole:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      dtPicker:['2023-08-23','2023-08-24']
    }
  },
  created() {
    const _from = dateAddDays(-7)
    const _to = parseDate(new Date())
    this.dtPicker = [_from,_to]
    console.log('datepickerInit-------',_from,_to)

    fetchList(this.listQuery).then(res=>{
      this.resList = res.flist
      console.log('fetchList-created----',res)

      this.getList()

    })
  },
  mounted() {
    var _userInfo = JSON.parse(getUserInfo())
    this.userInfoRoles = JSON.parse(_userInfo.U_Menu).role
    var _MEQGOptions = []
    var _MEQGCods = []
    var _MEQGDataInputRole = []

    console.log('--userInfoRoles-----------',_userInfo,this.userInfoRoles)
    if(this.userInfoRoles.indexOf('N1') >= 0)
    {
      _MEQGOptions.push({label:'HJ',value:'混胶工程'})
      _MEQGCods.push('HJ')
      _MEQGDataInputRole.push('HJ')
    }

    if(this.userInfoRoles.indexOf('N2') >= 0)
    {
      _MEQGOptions.push({label:'TB',value:'涂布工程'})
      _MEQGCods.push('TB')
      _MEQGDataInputRole.push('TB')
    }

    if(this.userInfoRoles.indexOf('N3') >= 0)
    {
      _MEQGOptions.push({label:'SH',value:'熟化工程'})
      _MEQGOptions.push({label:'FQ',value:'分切工程'})
      _MEQGCods.push('SH')
      _MEQGCods.push('FQ')
      _MEQGDataInputRole.push('SH')
      _MEQGDataInputRole.push('FQ')
    }

    if(this.userInfoRoles.indexOf('N4') >= 0)
    {
      if(_MEQGCods.indexOf('HJ')<0){
        _MEQGOptions.push({label:'HJ',value:'混胶工程'})
        _MEQGCods.push('HJ')
      }
      if(_MEQGCods.indexOf('TB')<0){
        _MEQGOptions.push({label:'TB',value:'涂布工程'})
        _MEQGCods.push('TB')
      }
      if(_MEQGCods.indexOf('SH')<0){
        _MEQGOptions.push({label:'SH',value:'熟化工程'})
        _MEQGOptions.push({label:'FQ',value:'分切工程'})
        _MEQGCods.push('SH')
        _MEQGCods.push('FQ')
      }
      _MEQGDataInputRole.push('ZL')
    }

    this.MEQGOptions = _MEQGOptions
    this.MEQGCods = _MEQGCods
    this.MEQGDataInputRole = _MEQGDataInputRole
    console.log('MEQGDataInputRole-----',this.MEQGDataInputRole)
  },
  activated (){
    fetchList(this.listQuery).then(res=>{
      this.resList = res.flist
      console.log('fetchList-activated----',res)

      this.getList()

    })
  },
  methods: {
    handleDownload() {
      this.downloadLoading = true
      import('@/utils/Export2Excel').then(excel => {
        const tHeader = ['单据号', '设备组', '设备编号', '批号', '产品', '产出数量', '投入数量']
        const filterVal = ['DocEntry', 'MEQG_Name', 'U_MEQU', 'lot_id', 'U_ItemCode', 'U_Qty', 'U_InQty']
        const list = this.flist
        const data = this.formatJson(filterVal, list)

        var filename = '生产实绩数据_' + this.dtPicker[0].replace(/-/g,'')+'_'+this.dtPicker[1].replace(/-/g,'')
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: filename,
          autoWidth: this.autoWidth,
          bookType: this.bookType
        })
        this.downloadLoading = false
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'timestamp') {
          return parseTime(v[j])
        } else {
          return v[j]
        }
      }))
    },
    handleChangeMEQG(val){
      this.curMEQGCode = val

      //console.log('handleChangeMEQG---------', val,this.resList)
      if(val != '' && val != undefined ){
        const _clist = this.resList.filter(v=>v.U_MEQG == val.trim()).map(v=>v.Code)
        //console.log('handleChangeMEQG--2-------', val, _clist)

        this.MEQUOptionsfilters = this.MEQUOptions.filter(item=>_clist.indexOf(item)>=0)
      }else{
        this.MEQUOptionsfilters = this.MEQUOptions
      }

    },
    datepickerChange(val){
      this.dtPicker = [parseDate(val[0]), parseDate(val[1])]
      console.log('datepickerChange-------', parseDate(val[0]), parseDate(val[1]))
    },
    handleFilter(){
      this.listQuery.page = 1
      console.log('handleFilter-----', this.listQuery)
      this.getList()
    },
    onSubmitBacktoLastProcess(){
      var that = this
      console.log('onSubmitBacktoLastProcess-----',this.curMPCP.DocEntry)
      that.$confirm('确定要撤销该LOT操作吗?', 'Warning', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {

          processBacktoPreviousMPCPs({
            key:that.curMPCP.DocEntry
          }).then(res=>{
            that.dialogTableVisible = false
            that.getList()
            console.log('processBacktoPreviousMPCPs--ok---',res)
            that.$message({
              type: 'success',
              message: '操作成功!'
            })
          }).catch(err=>{
            that.dialogTableVisible = false
            console.log('processBacktoPreviousMPCPs--err---',err)
          })

        })
        .catch(err => { console.error(err) })

    },
    gotoDetail(row){
      fetchMPCP1s().then(res => {
        console.log('fetchMPCP1s ok---------',row,res)
        this.mpcp1detail = res.filter(v=>v.DocEntry == row.DocEntry)
        this.curMPCP = row
        this.dialogTableVisible = true
      }).catch(err=>{
        console.log('fetchMPCP1s err---------',err)
      })
    },
    getList() {
      this.listLoading = true
      const { page = 1, limit = 20, U_MEQG, U_MEQU, U_MPCO, Canceled } = this.listQuery

      var config = {
        from: this.dtPicker[0],
        to: dateAddDays(1,this.dtPicker[1]),
        Canceled: Canceled,
        MEQG: U_MEQG,
        MEQU: U_MEQU,
        MPCO: U_MPCO
      }

      getAllMPCPendDataLists(config).then(res=>{
        console.log('getAllMPCPendDataLists-------------',res)
        var flist = []

        res.forEach((item,idx)=>{
          item.CreateDate = item.CreateDate.substr(0,4)+'-'+item.CreateDate.substr(4,2)+'-'+item.CreateDate.substr(6,2)
          if(flist.length == 0 || flist.filter(v=>v.DocEntry == item.DocEntry).length == 0){
            item.minDocEntry = item.DocEntry
            item.U_MEQG = item.MEQG_Code
            item.lot_id = item.U_MLOO.trim()
            item.scbh = item.sc1.substr(1,item.sc1.length)
            item.scbh_Existed = item.sc1.length>0
            item.scbh_docEntry = item.scDocEntry
            item.scbh_qty = item.scDocEntry.length>0 ? 1 : 0

            item.zlbh = item.zl1.substr(1,item.zl1.length)
            item.zlbh_Existed = item.zl1.length>0
            item.zlbh_docEntry = item.zlDocEntry
            item.zlbh_qty = item.zlDocEntry.length>0 ? 1 : 0

            flist.push(item)
          }else{
            var _eitem = flist.filter(v=>v.DocEntry == item.DocEntry)[0]
            _eitem.lot_id = item.U_MLOO + ','+ item.U_MLOO.trim()
            if(item.U_ItemCode != _eitem.U_ItemCode){
              _eitem.U_ItemCode = item.U_ItemCode + ','+ item.U_ItemCode.trim()
            }

            if(idx == res.length-1){
              flist.push(item)
            }
          }

        })

        var keepfqlots = flist.filter(v=>v.Canceled=='N' && v.U_OperParm=='keepfq').sort((a,b)=>{
          if(a.lot_id != b.lot_id) return a.lot_id.localeCompare(b.lot_id)
          return a.DocEntry.localeCompare(b.DocEntry)
        })

        var keepfqlist = []
        if(keepfqlots.length>0){
          keepfqlist.push(unique(keepfqlots.map(v=>v.lot_id)))
          var _minDocEntrys = []
          var _minDetails = []
          keepfqlist[0].forEach(item=>{
            var _minDoc = Math.min.apply(null,keepfqlots.filter(m=>m.lot_id == item).map(n=>n.DocEntry))
            _minDocEntrys.push(_minDoc)
            _minDetails.push(flist.filter(v=>v.DocEntry == _minDoc)[0])
          })
          keepfqlist.push(_minDocEntrys)
          keepfqlist.push(_minDetails)
          console.log('keepfqlist--------',keepfqlots.map(v=>v.lot_id),keepfqlots.map(v=>v.DocEntry),keepfqlist)

          flist = flist.map(item=>{
            var _minDocIdx = keepfqlist[0].indexOf(item.lot_id)
            if(_minDocIdx >= 0 && item.U_MEQG == 'FQ'){
              item.minDocEntry = keepfqlist[1][_minDocIdx]
              item.zlbh_qty = keepfqlist[2][_minDocIdx].zlbh_qty
              item.zlbh_docEntry = keepfqlist[2][_minDocIdx].zlbh_docEntry
            }
            return item
          })

        }


        if(this.curFilterLotId != ''){
          flist = flist.filter(v=>v.U_MLOO.indexOf(this.curFilterLotId)>=0)
        }

        if(this.curFilterMatId != ''){
          flist = flist.filter(v=>v.U_ItemCode.indexOf(this.curFilterMatId)>=0)
        }


        var curPageList = flist.filter((item, index) => index < limit * page && index >= limit * (page - 1))

        console.log('getAllMPCPendDataLists--curPageList-----------',flist,curPageList)

        this.MEQUOptions = [...new Set(flist.map(v=>v.U_MEQU).sort())]
        this.MPCOOptions = [...new Set(flist.map(v=>v.U_MPCO))]
        this.MEQUOptionsfilters = this.MEQUOptions

        this.list = curPageList
        this.flist = flist
        this.total = flist.length
        this.listLoading = false
      }).catch(err=>{
        console.log('getAllMPCPendDataLists--err-----------',err)
      })


      /* old code
      const _start = this.dtPicker[0]
      const _resList = this.resList

      fetchMPCP1s({}).then(res=>{
        //@MPCP1:DocEntry,LineId,U_MLOO,U_Ostate
        const _lots = res
        const _minDocEntry = res.sort((a,b)=>a.DocEntry - b.DocEntry).map(v=>v.DocEntry)[0]

        fetchMLOOsByDocEntry({minDocEntry:_minDocEntry}).then(resData=>{
          const mats = resData

          fetchEDCs(this.listQuery).then(resDt=>{
            const boudfs = resDt.flist

            fetchBouddGeDocEntry({minDocEntry:_minDocEntry}).then(resDt=>{
              const boudds = resDt  //生产数据,质检数据清单

              fetchMPCPends(this.listQuery).then(res => {
                var { flist, curPageList } = res
                const { page = 1, limit = 20 } = this.listQuery

                flist = flist.filter(v=>v.CreateDate >= this.dtPicker[0] && v.CreateDate <= this.dtPicker[1])

                flist.forEach(item=>{
                  var _resInfo = _resList.filter(v=>v.Code == item.U_MEQU)[0]
                  item.U_MEQG = _resInfo.U_MEQG
                  item.MEQG_Name = _resInfo.MEQG_Name
                  item.scbh = _resInfo.scbh
                  item.zlbh = _resInfo.zlbh

                  item.scbh_Existed = boudfs.filter(v=>v.Code == _resInfo.scbh).length >0 ? true : false
                  item.zlbh_Existed = boudfs.filter(v=>v.Code == _resInfo.zlbh).length >0 ? true : false
                })


                flist = flist.filter(v=>this.MEQGCods.indexOf(v.U_MEQG)>=0)

                if(this.listQuery.U_MEQG != ''){
                  flist = flist.filter(v=>v.U_MEQG == this.listQuery.U_MEQG)
                }

                if(this.listQuery.U_MEQU != ''){
                  flist = flist.filter(v=>v.U_MEQU == this.listQuery.U_MEQU)
                }

                flist.forEach(item=>{
                  var _sublots = _lots.filter(v=>v.DocEntry == item.DocEntry).map(v=>v.U_MLOO)
                  var _submats = mats.filter(v=>item.DocEntry == v.U_LastMPCP && _sublots.indexOf(v.Code)>=0)
                  if(_submats.length<=0){
                    _submats = mats.filter(v=>_sublots.indexOf(v.Code)>=0)
                  }

                  item.lot_id = _sublots.join(",")

                  item.U_ItemCode = _submats.map(v=>v.U_ItemCode).join(",")
                  item.U_Qty = _submats.map(v=>v.U_Qty).join(",")
                  item.U_InQty = _submats.map(v=>v.U_InQty).filter(m=>m.trim().length>0).join(",")

                  var _scbhInfo = boudds.filter(v=>v.U_BOUDF == item.scbh && v.U_RefEntry == item.DocEntry)
                  item.scbh_qty = _scbhInfo.length
                  item.scbh_docEntry = item.scbh_qty>0?_scbhInfo.DocEntry:''

                  var _zlbhInfo = boudds.filter(v=>v.U_BOUDF == item.zlbh && v.U_RefEntry == item.DocEntry)
                  item.zlbh_qty = _zlbhInfo.length
                  item.zlbh_docEntry = item.zlbh_qty>0?_zlbhInfo.DocEntry:''

                  item.minDocEntry = item.DocEntry
                })

                var keepfqlots = flist.filter(v=>v.Canceled=='N' && v.U_OperParm=='keepfq').sort((a,b)=>{
                  if(a.lot_id != b.lot_id) return a.lot_id.localeCompare(b.lot_id)
                  return a.DocEntry.localeCompare(b.DocEntry)
                })

                var keepfqlist = []
                if(keepfqlots.length>0){
                  keepfqlist.push(unique(keepfqlots.map(v=>v.lot_id)))
                  var _minDocEntrys = []
                  var _minDetails = []
                  keepfqlist[0].forEach(item=>{
                    var _minDoc = Math.min.apply(null,keepfqlots.filter(m=>m.lot_id == item).map(n=>n.DocEntry))
                    _minDocEntrys.push(_minDoc)
                    _minDetails.push(flist.filter(v=>v.DocEntry == _minDoc)[0])
                  })
                  keepfqlist.push(_minDocEntrys)
                  keepfqlist.push(_minDetails)
                  console.log('keepfqlots--------',keepfqlots.map(v=>v.lot_id),keepfqlots.map(v=>v.DocEntry),keepfqlist)

                  flist = flist.map(item=>{
                    var _minDocIdx = keepfqlist[0].indexOf(item.lot_id)
                    if(_minDocIdx >= 0 && item.U_MEQG == 'FQ'){
                      item.minDocEntry = keepfqlist[1][_minDocIdx]
                      item.zlbh_qty = keepfqlist[2][_minDocIdx].zlbh_qty
                      item.zlbh_docEntry = keepfqlist[2][_minDocIdx].zlbh_docEntry
                    }
                    return item
                  })

                }



                if(this.curFilterLotId != ''){
                  flist = flist.filter(v=>v.lot_id.indexOf(this.curFilterLotId)>=0)
                }

                if(this.curFilterMatId != ''){
                  flist = flist.filter(v=>v.U_ItemCode.indexOf(this.curFilterMatId)>=0)
                }

                curPageList = flist.filter((item, index) => index < limit * page && index >= limit * (page - 1))

                console.log('getList-------',curPageList)

                this.MEQUOptions = [...new Set(flist.map(v=>v.U_MEQU).sort())]
                this.MEQUOptionsfilters = this.MEQUOptions
                this.list = curPageList
                this.flist = flist
                this.total = flist.length
                this.listLoading = false
              })

            })

          })

        })

      })*/

    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
